package com.monitor.display_platform;

import com.monitor.display_platform.business.thread.*;
import com.monitor.display_platform.business.thread.v2.TaskLifeCycle;
import com.monitor.display_platform.business.thread.v2.impl.TaskLifeCycleImpl;
import com.monitor.display_platform.business.thread.v2.th.OneConsumer;
import com.monitor.display_platform.core.common.SpringApplicationContext;
import com.monitor.display_platform.core.exec.BaseThreadPoolExecutor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.ThreadPoolExecutor;

@SpringBootApplication
public class DisplayPlatformApplication {
    private static final Logger log = LoggerFactory.getLogger(DisplayPlatformApplication.class);

    public static void main(String[] args) {
        SpringApplication.run(DisplayPlatformApplication.class, args);
        doExecutor();
    }

    private static void doExecutor() {
        ExecutorService executor = SpringApplicationContext.getBean(ThreadPoolExecutor.class);
        log.info("添加任务完成 {}",executor.toString());
        TaskLifeCycle lifeCycle = new TaskLifeCycleImpl();
        for (int i = 0; i < 2; i++) {
            executor.execute(new OneConsumer(lifeCycle,()->"任务完成了。。。"));
        }
        for (int i = 0; i < 2; i++) {
            executor.execute(new SecondConsumer());
        }

        executor.execute(new ThreeConsumer());
        executor.execute(new FourConsumer());
        executor.execute(new FiveConsumer());
        log.info("添加任务完成 {}",executor.toString());



    }

}
